package org.jeecg.modules.third.jg.report.freight.information.util.sm;

import java.text.ParseException;
import java.util.Random;

public class UUIDGenerator {

	 /**
     * 生成lenght位的密钥
     * @param lenght 可变长度的密钥
     * @param ma    是否转换大小写，true大写，false小写
     * @return
     */
    static Random random = new Random();
    static String KeyValue_lenght(int lenght, boolean... ma) {
        //定义一个字符串（A-Z，a-z，0-9）即62位；
        String str = "zxcvbnmlkjhgfdsaqwertyuiopQWERTYUIOPASDFGHJKLZXCVBNM1234567890";
        //由Random生成随机数
        StringBuffer sb = new StringBuffer();
        //长度为几就循环几次
        for (int i = 0; i < lenght; ++i) {
            //产生0-61的数字
            int number = random.nextInt(62);
            //将产生的数字通过length次承载到sb中
            sb.append(str.charAt(number));
        }
        //将承载的字符转换成字符串
        return ma.length != 0 ? ma[0] ? sb.toString().toUpperCase() : sb.toString().toLowerCase() : sb.toString();
    }

    public static void main(String[] args) throws ParseException {
        System.out.println(KeyValue_lenght(64));
        System.out.println(KeyValue_lenght(64, true));
        System.out.println(KeyValue_lenght(64, false));

    	/*SimpleDateFormat sdf=new SimpleDateFormat("yyyyMMddHHmmss");
    	Date date = new Date();
    	long timeStart=date.getTime();
    	System.out.println(timeStart);
    	System.out.println(sdf.format(date));*/

    }

}
